package com.znsd.dining.room.utils;

import com.znsd.dining.room.response.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * @ClassName SendMailUtils
 * @Description:  邮箱发送
 * @Author timi
 * @Date 2020/1/2
 * @Time 16:13
 * @Version V1.0
 **/
public class SendMailUtils {
    
    @Autowired
    private static JavaMailSender javaMailSender;
    
    /**
     * @Author timi
     * @Description //邮件发送
     * @Date 16:22 2020/1/2
     * @Params
     * @return
     */
    public static ResultData sendMail(String from, String[] tos, String title, String content){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        // 发件人
        mailMessage.setFrom(from);
        //收件人
        mailMessage.setTo(tos);
        // 标题
        mailMessage.setSubject(title);
        // 发送内容
        mailMessage.setText(content);
        try{
            javaMailSender.send(mailMessage);
            return  ResultData.ok();
        }catch (RuntimeException run){
            return ResultData.error();
        }
    }
}
